from utils.operators.spark_submit import SparkSubmitOperator
from datetime import timedelta
from jms.ods import jms_ods__tab_platform_effect_config
from jms.ods.mysql.sys_manage_region import jms_ods__sys_manage_region
from jms.dm import jms_dm__dm_waybill_prescription_reach_details_dt
from jms.dim import jms_dim__dim_lmdm_sys_network_expand

jms_dm__dm_waybill_prescription_reach_details_platform_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_waybill_prescription_reach_details_platform_dt',
    email=['zhangqinglin@jtexpress.com','yl_bigdata@yl-scm.com'],
    pool_slots=4,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dm__dm_waybill_prescription_reach_details_platform_{{ execution_date | cst_ds }}',  # yarn 任务名称
    driver_memory='10G',
    executor_memory='16G',
    executor_cores=4,
    num_executors=100,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 150,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.default.parallelism': 1200,
          'spark.sql.shuffle.partitions': 1200
          },
    jars='hdfs:///scheduler/jms/spark/zql/prescription_reach/common-1.0-SNAPSHOT.jar',
    application='hdfs:///scheduler/jms/spark/zql/prescription_reach/original-jobs-1.0-SNAPSHOT.jar',
    java_class='com.yunlu.bigdata.jobs.export.WaybillPrescriptionReachPlatform',  # spark 主类
    application_args=['{{ execution_date | cst_ds }}'],  # 参数dt
    execution_timeout=timedelta(minutes=60),
)
# 设置依赖
jms_dm__dm_waybill_prescription_reach_details_platform_dt << [
    jms_dm__dm_waybill_prescription_reach_details_dt,
    jms_ods__tab_platform_effect_config,
    jms_ods__sys_manage_region,
    jms_dim__dim_lmdm_sys_network_expand
]
